// index.ts
// 获取应用实例
const app = getApp<IAppOption>()

Page({
  data: {
    showSkeleton: true,
    apiUrl: app.globalData.apiUrl,
    indicatorColor: "#ffffff",
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    theme: [],
    specialist: [],
    service: [],
    banner: [],

  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs',
    })
  },
  onLoad() {
    this.getIndex()
  },
  onShow() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
  },
  toArticleDetail(e: any) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../articleDetail/index?id=' + id,
    })
  },
  toSpecialistDetail(e: any) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../userDetail/index?id=' + id,
    })
  },
  toArticleList(e: any) {
    let category: number = e.currentTarget.dataset.category,
      title: String = e.currentTarget.dataset.title
    wx.navigateTo({
      url: '../articleList/index?category=' + category + '&title=' + title,
    })
  },
  toUserList(e: any) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../userList/index?id=' + id,
    })
  },
  getIndex() {
    let that = this;
    wx.request({
      url: app.globalData.apiUrl + 'api/index',
      success: function (res: any) {
        if (res.data.code == 0) {
          that.setData({
            banner: res.data.data.banner,
            theme: res.data.data.theme,
            service: res.data.data.service,
            specialist: res.data.data.specialist
          })
        }
      },
      complete: function () {
        that.setData({
          showSkeleton: false
        })
      }
    })
  }
})
export default app
